package com.java.rabbitmq.direct;

import com.java.rabbitmq.util.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author Woo_home
 * @create 2020/5/27 11:01
 */

public class TestProducer {

    private static final String QUEUE_NAME = "direct_queue";

    public static void main(String[] args) throws Exception {

        // 创建连接
        Connection connection = ConnectionUtils.getConnection();

        // 创建通道
        Channel channel = connection.createChannel();

        for (int i = 0; i < 100; i++) {
            String message = "direct 消息 " + i;
            // 发送消息到队列中
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes("utf-8"));
            System.out.println("发送消息：" + message);
        }
        // 关闭通道
        channel.close();
        connection.close();
    }
}
